#include "sqlite.hpp"
#include <cassert>

int select_stu_callback(void *arg, int col_count, char **result, char **fields_name)
{
    std::vector<std::string> *array = (std::vector<std::string> *) arg;
    array->push_back(result[0]);
    return 0;
}

int main()
{
    SqliteHelper helper("./test.db");
    // 创建/打开库文件
    assert(helper.open());
    // 创建表 学生信息: 学号, 姓名, 年龄
    const char *ct = "create table if not exists student(id int primary key, name varchar(32), age int)"; 
    assert(helper.exec(ct, nullptr, nullptr));
    // 增删查改
    // const char *insert_sql = "insert into student values(1, '薛姚一佳', 20), (2, '张宝龙', 21), (3, '田垒', 22);";
    // assert(helper.exec(insert_sql, nullptr, nullptr));

    // const char *update_sql = "update student set name = '雷雨桐' where id = 1";
    // assert(helper.exec(update_sql, nullptr, nullptr));

    // const char *delete_sql = "delete from student where id = 3";
    // assert(helper.exec(delete_sql, nullptr, nullptr));

    std::vector<std::string> array;
    const char *select_sql = "select name from student";
    assert(helper.exec(select_sql, select_stu_callback, &array));
    for(auto &v:array)
    {
        std::cout << v << std::endl;
    }

    // 关闭数据库
    helper.close();
    return 0;
}